<template>
  <div>
    <div
      class="sp_zero_tea"
      @click="st_tea_nav"
    >
      <div>
        <img
          :src="teacherData.lecturer.img"
          alt
        >
      </div>
      <div class="sp_ze_te_two">
        <div>{{teacherData.lecturer.name}}</div>
        <div>
          <span>{{teacherData.curriculum_count}}</span> 课程数
          <span>{{teacherData.follow_count}}</span> 关注
        </div>
      </div>
      <div>
        <span
          class="sp_zt_true"
          v-if="state == 0"
          @click.stop="sp_follow_click(teacherData.lecturer.lecturer_id,1)"
        >关注</span>
        <span
          class="sp_zt_false"
          v-else
          @click.stop="sp_follow_click(teacherData.lecturer.lecturer_id,0)"
        >已关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import {
  follow_lecturer
} from '@/api/coursedetails'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      state: ''
    }
  },
  computed: {
    ...mapState({
      user_id: state => state.member_id
    })
  },
  props: ['teacherData'],
  created () {
    this.state = this.teacherData.follow
    console.log(this.teacherData)
  },
  methods: {
    st_tea_nav () {
      console.log(this.teacherData.lecturer.lecturer_id)
      this.$router.push({
        path: '/teacher',
        query: {
          lecturer_id: this.teacherData.lecturer.lecturer_id
        }
      })
    },
    sp_follow_click (lecturerId, nu) {
      this.state = nu
      let requery = {
        user_id: this.user_id,
        lecturer_id: lecturerId
      }
      follow_lecturer(requery).then(res => {
        let { code } = res.data
        if (code === 200) {
          this.$emit('okTeacher', true, nu)
        } else {
          this.$emit('okTeacher', false, nu)
          alert(res.data.msg)
        }
      })
    }
  },
  components: {

  }
}
</script>

<style scoped>
.sp_zero_list {
  width: 90%;
  margin: 0 5%;
}

.sp_zero_tea {
  width: 90%;
  height: 76px;
  // border-top: 1px solid #eeeeee;
  // border-bottom: 1px solid #eeeeee;
  margin: 0px 5%;
  display: flex;
}

.sp_zero_tea > div:nth-child(1) {
  width: 66px;
}

.sp_zero_tea > div:nth-child(1) img {
  width: 50px;
  height: 50px;
  margin: 12px 5px;
  border-radius: 50%;
}

.sp_zero_tea > div:nth-child(2) {
  flex: 2;
}

.sp_zero_tea > div:nth-child(3) {
  flex: 1;
}

.sp_ze_te_two > div:nth-child(1) {
  height: 40px;
  line-height: 55px;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: bold;
}

.sp_ze_te_two > div:nth-child(2) {
  font-size: 12px;
  color: #999999;
}

.sp_ze_te_two > div:nth-child(2) span {
  display: inline-block;
  font-size: 12px;
  color: #1a1a1a;
}

.sp_ze_te_two > div:nth-child(2) span:nth-child(2) {
  margin-left: 10px;
}

.sp_zt_true {
  display: block;
  width: calc(100vw * 140 / 750);
  height: calc(100vw * 54 / 750);
  line-height: calc(100vw * 54 / 750);
  background: #da4131;
  color: white;
  font-size: 15px;
  text-align: center;
  margin: 20px 5%;
  border-radius: 500px;
}

.sp_zt_false {
  display: block;
  width: calc(100vw * 140 / 750);
  height: calc(100vw * 54 / 750);
  line-height: calc(100vw * 54 / 750);
  border: 1px solid #da4131;
  text-align: center;
  font-size: 15px;
  color: #da4131;
  border-radius: 500px;
  margin: 20px 5%;
}
</style>
